<!DOCTYPE html>


<html lang="zh-CN">


<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    Python采集linux服务器数据在Django Web界面展示.md |  
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

</head>

</html>

<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-develop/Python采集linux服务器数据在Django Web界面展示"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  Python采集linux服务器数据在Django Web界面展示.md
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/11/11/develop/Python%E9%87%87%E9%9B%86linux%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%95%B0%E6%8D%AE%E5%9C%A8Django%20Web%E7%95%8C%E9%9D%A2%E5%B1%95%E7%A4%BA/" class="article-date">
  <time datetime="2020-11-10T16:00:00.000Z" itemprop="datePublished">2020-11-11</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/develop/">develop</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">2.7k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">15 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="Python采集linux服务器数据在Django-Web界面展示"><a href="#Python采集linux服务器数据在Django-Web界面展示" class="headerlink" title="Python采集linux服务器数据在Django Web界面展示"></a>Python采集linux服务器数据在Django Web界面展示</h1><h3 id="Django显示服务器性能监控"><a href="#Django显示服务器性能监控" class="headerlink" title="Django显示服务器性能监控"></a>Django显示服务器性能监控</h3><ul>
<li><ul>
<li><p>监控系统CPU、内存和进程信息</p>
</li>
<li><ul>
<li>一、运行环境与项目目录</li>
<li>二、配置文档：Setting</li>
<li>二、创建 Models，操作数据</li>
<li>三、创建数据库</li>
<li>四、 views.py</li>
<li>五、创建html模版</li>
<li>六、urls.py添加路由</li>
<li>七、运行程序，显示结果</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="监控系统CPU、内存和进程信息"><a href="#监控系统CPU、内存和进程信息" class="headerlink" title="监控系统CPU、内存和进程信息"></a>监控系统CPU、内存和进程信息</h2><h3 id="一、运行环境与项目目录"><a href="#一、运行环境与项目目录" class="headerlink" title="一、运行环境与项目目录"></a>一、运行环境与项目目录</h3><ol>
<li>Django 2.0.7</li>
<li>python 3.7</li>
<li>pymysql 0.9.3</li>
</ol>
<p><img src="http://iubest.gitee.io/pic/640-1601016028012.webp" alt="img"></p>
<h3 id="二、配置文档：Setting"><a href="#二、配置文档：Setting" class="headerlink" title="二、配置文档：Setting"></a>二、配置文档：Setting</h3><p>1.mysql 数据库</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"># Author: Allan</span><br><span class="line"># Datetime: 2019-05-21</span><br><span class="line">import pymysql</span><br><span class="line">pymysql.install_as_MySQLdb()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">DATABASES &#x3D; &#123;</span><br><span class="line">    &#39;default&#39;: &#123;</span><br><span class="line">        # 注释sqlite3</span><br><span class="line">        # &#39;ENGINE&#39;: &#39;django.db.backends.sqlite3&#39;,</span><br><span class="line">        # &#39;NAME&#39;: os.path.join(BASE_DIR, &#39;db.sqlite3&#39;),</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        # mysql</span><br><span class="line">        &#39;ENGINE&#39;: &#39;django.db.backends.mysql&#39;,</span><br><span class="line">        &#39;NAME&#39;: &#39;database&#39;,</span><br><span class="line">        &#39;USER&#39;: &#39;username&#39;,</span><br><span class="line">        &#39;PASSWORD&#39;: &#39;password&#39;,</span><br><span class="line">        &#39;HOST&#39;: &#39;ip&#39;,</span><br><span class="line">        &#39;PORT&#39;: 3306,</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>2.Application definition</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">INSTALLED_APPS &#x3D; [</span><br><span class="line">   &#39;django.contrib.admin&#39;,</span><br><span class="line">   &#39;django.contrib.auth&#39;,</span><br><span class="line">   &#39;django.contrib.contenttypes&#39;,</span><br><span class="line">   &#39;django.contrib.sessions&#39;,</span><br><span class="line">   &#39;django.contrib.messages&#39;,</span><br><span class="line">   &#39;django.contrib.staticfiles&#39;,</span><br><span class="line">   &#39;web&#39;  #添加App，下面python3 mkmigrations web使用</span><br><span class="line">]</span><br><span class="line"></span><br><span class="line">MIDDLEWARE &#x3D; [</span><br><span class="line">   &#39;django.middleware.security.SecurityMiddleware&#39;,</span><br><span class="line">   &#39;django.contrib.sessions.middleware.SessionMiddleware&#39;,</span><br><span class="line">   &#39;django.middleware.common.CommonMiddleware&#39;,</span><br><span class="line">   # &#39;django.middleware.csrf.CsrfViewMiddleware&#39;, 注释这一行，防止403错误</span><br><span class="line">   &#39;django.contrib.auth.middleware.AuthenticationMiddleware&#39;,</span><br><span class="line">   &#39;django.contrib.messages.middleware.MessageMiddleware&#39;,</span><br><span class="line">   &#39;django.middleware.clickjacking.XFrameOptionsMiddleware&#39;,</span><br><span class="line">]</span><br><span class="line"></span><br><span class="line">ROOT_URLCONF &#x3D; &#39;monitor.urls&#39;</span><br><span class="line"></span><br><span class="line">TEMPLATES &#x3D; [</span><br><span class="line">   &#123;</span><br><span class="line">       &#39;BACKEND&#39;: &#39;django.template.backends.django.DjangoTemplates&#39;,</span><br><span class="line">       &#39;DIRS&#39;: [os.path.join(BASE_DIR, &#39;templates&#39;)],  #修改模版目录</span><br><span class="line">       &#39;APP_DIRS&#39;: True,</span><br><span class="line">       &#39;OPTIONS&#39;: &#123;</span><br><span class="line">           &#39;context_processors&#39;: [</span><br><span class="line">               &#39;django.template.context_processors.debug&#39;,</span><br><span class="line">               &#39;django.template.context_processors.request&#39;,</span><br><span class="line">               &#39;django.contrib.auth.context_processors.auth&#39;,</span><br><span class="line">               &#39;django.contrib.messages.context_processors.messages&#39;,</span><br><span class="line">           ],</span><br><span class="line">       &#125;,</span><br><span class="line">   &#125;,</span><br><span class="line">]</span><br></pre></td></tr></table></figure>

<p>3.Security</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"># SECURITY WARNING: don&#39;t run with debug turned on in production!</span><br><span class="line">DEBUG &#x3D; True</span><br><span class="line"></span><br><span class="line">ALLOWED_HOSTS &#x3D; [&#39;*&#39;]</span><br></pre></td></tr></table></figure>

<p>4.Internationalization</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">LANGUAGE_CODE &#x3D; &#39;en-us&#39;</span><br><span class="line"># 修改时区</span><br><span class="line">TIME_ZONE &#x3D; &#39;Asia&#x2F;Shanghai&#39;</span><br><span class="line"></span><br><span class="line">USE_I18N &#x3D; True</span><br><span class="line"></span><br><span class="line">USE_L10N &#x3D; True</span><br><span class="line"># 修改时区</span><br><span class="line">USE_TZ &#x3D; False</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="二、创建-Models，操作数据"><a href="#二、创建-Models，操作数据" class="headerlink" title="二、创建 Models，操作数据"></a>二、创建 Models，操作数据</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">from django.db import models</span><br><span class="line"></span><br><span class="line"># Create your models here.</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">class CpuInfo(models.Model):</span><br><span class="line">    # CPU信息</span><br><span class="line">    time &#x3D; models.DateTimeField()</span><br><span class="line">    host &#x3D; models.CharField(max_length&#x3D;40)</span><br><span class="line">    usage_system &#x3D; models.FloatField(null&#x3D;True)</span><br><span class="line">    usage_user &#x3D; models.FloatField(null&#x3D;True)</span><br><span class="line">    usage_softirq &#x3D; models.FloatField(null&#x3D;True)</span><br><span class="line">    usage_iowait &#x3D; models.FloatField(null&#x3D;True)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">class MemoryInfo(models.Model):</span><br><span class="line">    #内存信息</span><br><span class="line">    time &#x3D; models.DateTimeField()</span><br><span class="line">    host &#x3D; models.CharField(max_length&#x3D;40)</span><br><span class="line">    used_percent &#x3D; models.FloatField(null&#x3D;True)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">class ProcstatInfo(models.Model):</span><br><span class="line">    # 进程信息</span><br><span class="line">    time &#x3D; models.DateTimeField()</span><br><span class="line">    host &#x3D; models.CharField(max_length&#x3D;100)</span><br><span class="line">    exe &#x3D; models.CharField(max_length&#x3D;40)</span><br><span class="line">    pid &#x3D; models.FloatField()</span><br><span class="line">    cpu_usage &#x3D; models.FloatField(null&#x3D;True)</span><br><span class="line">    memory_rss &#x3D; models.FloatField(null&#x3D;True)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="三、创建数据库"><a href="#三、创建数据库" class="headerlink" title="三、创建数据库"></a>三、创建数据库</h3><p>1.Terminal 下运行manager.py</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"># python3 manager.py mkmigrations web</span><br><span class="line"># python3 manager.py migrate</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>2.查询mysql</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">mysql&gt; show tables;</span><br><span class="line">ERROR 2006 (HY000): MySQL server has gone away</span><br><span class="line">No connection. Trying to reconnect...</span><br><span class="line">Connection id:    449745</span><br><span class="line">Current database: perf_monitor</span><br><span class="line"></span><br><span class="line">+----------------------------+</span><br><span class="line">| Tables_in_perf_monitor     |</span><br><span class="line">+----------------------------+</span><br><span class="line">| auth_group                 |</span><br><span class="line">| auth_group_permissions     |</span><br><span class="line">| auth_permission            |</span><br><span class="line">| auth_user                  |</span><br><span class="line">| auth_user_groups           |</span><br><span class="line">| auth_user_user_permissions |</span><br><span class="line">| django_admin_log           |</span><br><span class="line">| django_content_type        |</span><br><span class="line">| django_migrations          |</span><br><span class="line">| django_session             |</span><br><span class="line">| web_cpuinfo                |</span><br><span class="line">| web_memoryinfo             |</span><br><span class="line">| web_procstatinfo           |</span><br><span class="line">+----------------------------+</span><br><span class="line">13 rows in set (0.51 sec)</span><br><span class="line"></span><br><span class="line">mysql&gt; </span><br></pre></td></tr></table></figure>

<p><strong>四、</strong> views.py</p>
<p>创建两个views，一个显示CPU和内存信息；另一个现实进程信息</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"># Author: Allan</span><br><span class="line"># Datetime: 2019-05-21</span><br><span class="line">import time</span><br><span class="line">import json</span><br><span class="line">from django.shortcuts import render</span><br><span class="line">from web import models</span><br><span class="line"></span><br><span class="line"># Create your views here.</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def show_procstat(request):</span><br><span class="line">    servers &#x3D; [&#39;rotestZone01&#39;, &#39;rotestZone02&#39;]</span><br><span class="line">    procstat_ret &#x3D; &#123;&#125;</span><br><span class="line">    for server in servers:</span><br><span class="line">        procstat_info &#x3D; models.ProcstatInfo.objects.filter(host&#x3D;server)</span><br><span class="line">        procstat_exe &#x3D; &#123;&#125;</span><br><span class="line">        for row in procstat_info:</span><br><span class="line">            temp_time &#x3D; int(time.mktime(row.time.timetuple())) * 1000</span><br><span class="line">            key &#x3D; str(row.exe) + &#39;_&#39; + str(int(row.pid))</span><br><span class="line">            if key not in procstat_exe:</span><br><span class="line">                procstat_exe[key] &#x3D; &#123;&#125;</span><br><span class="line">                procstat_exe[key][&#39;cpu_usage&#39;] &#x3D; []</span><br><span class="line">                procstat_exe[key][&#39;memory_rss&#39;] &#x3D; []</span><br><span class="line">            procstat_exe[key][&#39;cpu_usage&#39;].append([temp_time, row.cpu_usage])</span><br><span class="line">            procstat_exe[key][&#39;memory_rss&#39;].append([temp_time, row.memory_rss])</span><br><span class="line">        procstat_ret[server] &#x3D; procstat_exe</span><br><span class="line"></span><br><span class="line">    return render(request, &#39;show_procstat.html&#39;, &#123;&quot;procstat_ret&quot;: json.dumps(procstat_ret)&#125;)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def show_servers(request):</span><br><span class="line">    servers &#x3D; [&#39;rotestZone01&#39;, &#39;rotestZone02&#39;]</span><br><span class="line">    server_res &#x3D; &#123;&#125;</span><br><span class="line">    cpu_res &#x3D; &#123;&#125;</span><br><span class="line">    mem_res &#x3D; &#123;&#125;</span><br><span class="line">    for server in servers:</span><br><span class="line">        cpu_info &#x3D; models.CpuInfo.objects.filter(host&#x3D;server)</span><br><span class="line">        cpu_ret &#x3D; &#123;&#125;</span><br><span class="line">        usage_system &#x3D; []</span><br><span class="line">        usage_user &#x3D; []</span><br><span class="line">        usage_softirq &#x3D; []</span><br><span class="line">        usage_iowait &#x3D; []</span><br><span class="line">        for row in cpu_info:</span><br><span class="line">            temp_time &#x3D; int(time.mktime(row.time.timetuple())) * 1000</span><br><span class="line">            usage_system.append([temp_time, row.usage_system])</span><br><span class="line">            usage_user.append([temp_time, row.usage_user])</span><br><span class="line">            usage_softirq.append([temp_time, row.usage_softirq])</span><br><span class="line">            usage_iowait.append([temp_time, row.usage_iowait])</span><br><span class="line">        cpu_ret[&#39;usage_system&#39;] &#x3D; usage_system</span><br><span class="line">        cpu_ret[&#39;usage_user&#39;] &#x3D; usage_user</span><br><span class="line">        cpu_ret[&#39;usage_softirq&#39;] &#x3D; usage_softirq</span><br><span class="line">        cpu_ret[&#39;usage_iowait&#39;] &#x3D; usage_iowait</span><br><span class="line">        cpu_res[server] &#x3D; cpu_ret</span><br><span class="line"></span><br><span class="line">        mem_info &#x3D; models.MemoryInfo.objects.filter(host&#x3D;server)</span><br><span class="line">        mem_ret &#x3D; []</span><br><span class="line">        for row in mem_info:</span><br><span class="line">            temp_time &#x3D; int(time.mktime(row.time.timetuple()))*1000</span><br><span class="line">            mem_ret.append([temp_time, row.used_percent])</span><br><span class="line">        mem_res[server] &#x3D; mem_ret</span><br><span class="line"></span><br><span class="line">    server_res[&#39;cpu_res&#39;] &#x3D; cpu_res</span><br><span class="line">    server_res[&#39;mem_res&#39;] &#x3D; mem_res</span><br><span class="line"></span><br><span class="line">    return render(request, &#39;show_servers.html&#39;, &#123;&quot;server_res&quot;: json.dumps(server_res)&#125;)</span><br></pre></td></tr></table></figure>

<p><strong>五、创建html模版</strong></p>
<p>创建两个html模版，一个显示CPU和内存信息；另一个现实进程信息</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">&lt;html xmlns&#x3D;&quot;http:&#x2F;&#x2F;www.w3.org&#x2F;1999&#x2F;html&quot;&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">&lt;meta charset&#x3D;&quot;UTF-8&quot; &#x2F;&gt;</span><br><span class="line">&lt;title&gt;服务器监控信息&lt;&#x2F;title&gt;</span><br><span class="line">&lt;script src&#x3D;&quot;https:&#x2F;&#x2F;code.jquery.com&#x2F;jquery-3.1.1.min.js&quot;&gt;&lt;&#x2F;script&gt;</span><br><span class="line">&lt;script src&#x3D;&quot;https:&#x2F;&#x2F;code.highcharts.com&#x2F;highcharts.js&quot;&gt;&lt;&#x2F;script&gt;</span><br><span class="line">&lt;script src&#x3D;&quot;https:&#x2F;&#x2F;code.highcharts.com&#x2F;modules&#x2F;exporting.js&quot;&gt;&lt;&#x2F;script&gt;</span><br><span class="line">&lt;script src&#x3D;&quot;https:&#x2F;&#x2F;code.highcharts.com&#x2F;modules&#x2F;export-data.js&quot;&gt;&lt;&#x2F;script&gt;</span><br><span class="line">&lt;script language&#x3D;&quot;JavaScript&quot;&gt;</span><br><span class="line">$(document).ready(function() &#123;</span><br><span class="line">    $(&quot;#servers&quot;).change(function ()&#123;</span><br><span class="line">        var selected &#x3D; $(this).children(&#39;option:selected&#39;).val();</span><br><span class="line">        var server_res &#x3D; jQuery.parseJSON(&#39;&#123;&#123; server_res|safe &#125;&#125;&#39;);</span><br><span class="line"></span><br><span class="line">        var cpu_res &#x3D; server_res[&#39;cpu_res&#39;]</span><br><span class="line">        var cpu_info &#x3D; cpu_res[selected]</span><br><span class="line"></span><br><span class="line">        Highcharts.setOptions(&#123;</span><br><span class="line">            global:&#123;</span><br><span class="line">                useUTC: false</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;);</span><br><span class="line">        Highcharts.chart(&#39;cpu&#39;, &#123;</span><br><span class="line">            chart: &#123;</span><br><span class="line">                zoomType: &#39;x&#39;</span><br><span class="line">            &#125;,</span><br><span class="line">            title: &#123;</span><br><span class="line">                text: selected + &#39;: CPU 信息&#39;</span><br><span class="line">            &#125;,</span><br><span class="line">            subtitle: &#123;</span><br><span class="line">                text: document.ontouchstart &#x3D;&#x3D;&#x3D; undefined ?</span><br><span class="line">                    &#39;Click and drag in the plot area to zoom in&#39; : &#39;Pinch the chart to zoom in&#39;</span><br><span class="line">            &#125;,</span><br><span class="line">            xAxis: &#123;</span><br><span class="line">                type: &#39;datetime&#39;</span><br><span class="line">            &#125;,</span><br><span class="line">            yAxis: &#123;</span><br><span class="line">                title: &#123;</span><br><span class="line">                    text: &#39;使用率 (%)&#39;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;,</span><br><span class="line">            legend: &#123;</span><br><span class="line">                enabled: false</span><br><span class="line">            &#125;,</span><br><span class="line">            plotOptions: &#123;</span><br><span class="line">                area: &#123;</span><br><span class="line">                    fillColor: &#123;</span><br><span class="line">                        linearGradient: &#123;</span><br><span class="line">                            x1: 0,</span><br><span class="line">                            y1: 0,</span><br><span class="line">                            x2: 0,</span><br><span class="line">                            y2: 1</span><br><span class="line">                        &#125;,</span><br><span class="line">                        stops: [</span><br><span class="line">                            [0, Highcharts.getOptions().colors[0]],</span><br><span class="line">                            [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get(&#39;rgba&#39;)]</span><br><span class="line">                        ]</span><br><span class="line">                    &#125;,</span><br><span class="line">                    marker: &#123;</span><br><span class="line">                        radius: 2</span><br><span class="line">                    &#125;,</span><br><span class="line">                    lineWidth: 1,</span><br><span class="line">                    states: &#123;</span><br><span class="line">                        hover: &#123;</span><br><span class="line">                            lineWidth: 1</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;,</span><br><span class="line">                    threshold: null</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;,</span><br><span class="line"></span><br><span class="line">            series: [</span><br><span class="line">                &#123;</span><br><span class="line">                   type: &#39;area&#39;,</span><br><span class="line">                   name: &#39;usage_system&#39;,</span><br><span class="line">                   data: cpu_info[&#39;usage_system&#39;]</span><br><span class="line">                &#125;,</span><br><span class="line">                &#123;</span><br><span class="line">                   type: &#39;area&#39;,</span><br><span class="line">                   name: &#39;usage_user&#39;,</span><br><span class="line">                   data: cpu_info[&#39;usage_user&#39;]</span><br><span class="line">                &#125;,</span><br><span class="line">                &#123;</span><br><span class="line">                   type: &#39;area&#39;,</span><br><span class="line">                   name: &#39;usage_softirq&#39;,</span><br><span class="line">                   data: cpu_info[&#39;usage_softirq&#39;]</span><br><span class="line">                &#125;,</span><br><span class="line">                &#123;</span><br><span class="line">                   type: &#39;area&#39;,</span><br><span class="line">                   name: &#39;usage_iowait&#39;,</span><br><span class="line">                   data: cpu_info[&#39;usage_iowait&#39;]</span><br><span class="line">                &#125;]</span><br><span class="line">        &#125;);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        var mem_res &#x3D; server_res[&#39;mem_res&#39;]</span><br><span class="line">        var mem_info &#x3D; mem_res[selected]</span><br><span class="line">        Highcharts.chart(&#39;mem&#39;, &#123;</span><br><span class="line">            chart: &#123;</span><br><span class="line">                zoomType: &#39;x&#39;</span><br><span class="line">            &#125;,</span><br><span class="line">            title: &#123;</span><br><span class="line">                text: selected + &#39;: 内存信息&#39;</span><br><span class="line">            &#125;,</span><br><span class="line">            subtitle: &#123;</span><br><span class="line">                text: document.ontouchstart &#x3D;&#x3D;&#x3D; undefined ?</span><br><span class="line">                    &#39;Click and drag in the plot area to zoom in&#39; : &#39;Pinch the chart to zoom in&#39;</span><br><span class="line">            &#125;,</span><br><span class="line">            xAxis: &#123;</span><br><span class="line">                type: &#39;datetime&#39;</span><br><span class="line">            &#125;,</span><br><span class="line">            yAxis: &#123;</span><br><span class="line">                title: &#123;</span><br><span class="line">                    text: &#39;使用率 (%)&#39;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;,</span><br><span class="line">            legend: &#123;</span><br><span class="line">                enabled: false</span><br><span class="line">            &#125;,</span><br><span class="line">            plotOptions: &#123;</span><br><span class="line">                area: &#123;</span><br><span class="line">                    fillColor: &#123;</span><br><span class="line">                        linearGradient: &#123;</span><br><span class="line">                            x1: 0,</span><br><span class="line">                            y1: 0,</span><br><span class="line">                            x2: 0,</span><br><span class="line">                            y2: 1</span><br><span class="line">                        &#125;,</span><br><span class="line">                        stops: [</span><br><span class="line">                            [0, Highcharts.getOptions().colors[0]],</span><br><span class="line">                            [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get(&#39;rgba&#39;)]</span><br><span class="line">                        ]</span><br><span class="line">                    &#125;,</span><br><span class="line">                    marker: &#123;</span><br><span class="line">                        radius: 2</span><br><span class="line">                    &#125;,</span><br><span class="line">                    lineWidth: 1,</span><br><span class="line">                    states: &#123;</span><br><span class="line">                        hover: &#123;</span><br><span class="line">                            lineWidth: 1</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;,</span><br><span class="line">                    threshold: null</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;,</span><br><span class="line"></span><br><span class="line">            series: [&#123;</span><br><span class="line">                type: &#39;area&#39;,</span><br><span class="line">                name: &#39;used_percent&#39;,</span><br><span class="line">                data: mem_info</span><br><span class="line">            &#125;]</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;);</span><br><span class="line">&lt;&#x2F;script&gt;</span><br><span class="line">&lt;&#x2F;head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">&lt;div&gt;&lt;H2&gt;服务器监控信息&lt;&#x2F;H2&gt;&lt;&#x2F;div&gt;</span><br><span class="line">&lt;select id&#x3D;&quot;servers&quot;&gt;</span><br><span class="line">    &lt;option value&#x3D;&quot;servers&quot;&gt;请选择要监控的服务器&lt;&#x2F;option&gt;</span><br><span class="line">    &lt;option value&#x3D;&quot;rotestZone01&quot;&gt;rotestZone01&lt;&#x2F;option&gt;</span><br><span class="line">    &lt;option value&#x3D;&quot;rotestZone02&quot;&gt;rotestZone02&lt;&#x2F;option&gt;</span><br><span class="line">&lt;&#x2F;select&gt;</span><br><span class="line"></span><br><span class="line">&lt;div id&#x3D;&quot;cpu&quot; style&#x3D;&quot;width: 1560px; height: 400px; margin: 0 auto&quot;&gt;&lt;&#x2F;div&gt;</span><br><span class="line">&lt;div id&#x3D;&quot;mem&quot; style&#x3D;&quot;width: 1560px; height: 400px; margin: 0 auto&quot;&gt;&lt;&#x2F;div&gt;</span><br><span class="line">&lt;&#x2F;body&gt;</span><br><span class="line">&lt;&#x2F;html&gt;</span><br></pre></td></tr></table></figure>



<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br></pre></td><td class="code"><pre><span class="line">&lt;html xmlns&#x3D;&quot;http:&#x2F;&#x2F;www.w3.org&#x2F;1999&#x2F;html&quot; xmlns&#x3D;&quot;http:&#x2F;&#x2F;www.w3.org&#x2F;1999&#x2F;html&quot;&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">&lt;meta charset&#x3D;&quot;UTF-8&quot; &#x2F;&gt;</span><br><span class="line">&lt;title&gt;服务器监控信息&lt;&#x2F;title&gt;</span><br><span class="line">&lt;script src&#x3D;&quot;https:&#x2F;&#x2F;code.jquery.com&#x2F;jquery-3.1.1.min.js&quot;&gt;&lt;&#x2F;script&gt;</span><br><span class="line">&lt;script src&#x3D;&quot;https:&#x2F;&#x2F;code.highcharts.com&#x2F;highcharts.js&quot;&gt;&lt;&#x2F;script&gt;</span><br><span class="line">&lt;script src&#x3D;&quot;https:&#x2F;&#x2F;code.highcharts.com&#x2F;modules&#x2F;exporting.js&quot;&gt;&lt;&#x2F;script&gt;</span><br><span class="line">&lt;script src&#x3D;&quot;https:&#x2F;&#x2F;code.highcharts.com&#x2F;modules&#x2F;export-data.js&quot;&gt;&lt;&#x2F;script&gt;</span><br><span class="line">&lt;script language&#x3D;&quot;JavaScript&quot;&gt;</span><br><span class="line">$(document).ready(function() &#123;</span><br><span class="line">    $(&quot;#servers&quot;).change(function ()&#123;</span><br><span class="line">        var selected &#x3D; $(this).children(&#39;option:selected&#39;).val();</span><br><span class="line">        var server_res &#x3D; jQuery.parseJSON(&#39;&#123;&#123; procstat_ret|safe &#125;&#125;&#39;);</span><br><span class="line">        var xServers &#x3D; server_res[selected]</span><br><span class="line"></span><br><span class="line">        var obj&#x3D;document.getElementById(&#39;processes&#39;);</span><br><span class="line">        if (obj.options.length !&#x3D; 1)&#123;</span><br><span class="line">            obj.options.length&#x3D;1;</span><br><span class="line">        &#125;</span><br><span class="line">        for(var key in xServers)</span><br><span class="line">        &#123;</span><br><span class="line">            obj.options.add(new Option(key,key));</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        $(&quot;#processes&quot;).change(function ()&#123;</span><br><span class="line">            var procSelected &#x3D; $(this).children(&#39;option:selected&#39;).val();</span><br><span class="line">            var dataMem &#x3D; new Array();</span><br><span class="line">            var dataCpu &#x3D; new Array();</span><br><span class="line">            for(var key in xServers)</span><br><span class="line">                &#123;</span><br><span class="line">                    if (key &#x3D;&#x3D; procSelected)&#123;</span><br><span class="line">                        dataCpu &#x3D; xServers[key][&#39;cpu_usage&#39;]</span><br><span class="line">                        dataMem &#x3D; xServers[key][&#39;memory_rss&#39;];</span><br><span class="line">                        break;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            Highcharts.chart(&#39;cpu&#39;, &#123;</span><br><span class="line">            chart: &#123;</span><br><span class="line">                zoomType: &#39;x&#39;</span><br><span class="line">            &#125;,</span><br><span class="line">            title: &#123;</span><br><span class="line">                text: selected + &#39;: CPU 信息&#39;</span><br><span class="line">            &#125;,</span><br><span class="line">            subtitle: &#123;</span><br><span class="line">                text: document.ontouchstart &#x3D;&#x3D;&#x3D; undefined ?</span><br><span class="line">                    &#39;Click and drag in the plot area to zoom in&#39; : &#39;Pinch the chart to zoom in&#39;</span><br><span class="line">            &#125;,</span><br><span class="line">            xAxis: &#123;</span><br><span class="line">                type: &#39;datetime&#39;</span><br><span class="line">            &#125;,</span><br><span class="line">            yAxis: &#123;</span><br><span class="line">                title: &#123;</span><br><span class="line">                    text: &#39;使用率 (%)&#39;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;,</span><br><span class="line">            legend: &#123;</span><br><span class="line">                enabled: false</span><br><span class="line">            &#125;,</span><br><span class="line">            plotOptions: &#123;</span><br><span class="line">                area: &#123;</span><br><span class="line">                    fillColor: &#123;</span><br><span class="line">                        linearGradient: &#123;</span><br><span class="line">                            x1: 0,</span><br><span class="line">                            y1: 0,</span><br><span class="line">                            x2: 0,</span><br><span class="line">                            y2: 1</span><br><span class="line">                        &#125;,</span><br><span class="line">                        stops: [</span><br><span class="line">                            [0, Highcharts.getOptions().colors[0]],</span><br><span class="line">                            [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get(&#39;rgba&#39;)]</span><br><span class="line">                        ]</span><br><span class="line">                    &#125;,</span><br><span class="line">                    marker: &#123;</span><br><span class="line">                        radius: 2</span><br><span class="line">                    &#125;,</span><br><span class="line">                    lineWidth: 1,</span><br><span class="line">                    states: &#123;</span><br><span class="line">                        hover: &#123;</span><br><span class="line">                            lineWidth: 1</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;,</span><br><span class="line">                    threshold: null</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;,</span><br><span class="line"></span><br><span class="line">            series: [</span><br><span class="line">                &#123;</span><br><span class="line">                   type: &#39;area&#39;,</span><br><span class="line">                   name: &#39;cpu_usage&#39;,</span><br><span class="line">                   data: dataCpu</span><br><span class="line">                &#125;]</span><br><span class="line">            &#125;);</span><br><span class="line"></span><br><span class="line">            Highcharts.chart(&#39;mem&#39;, &#123;</span><br><span class="line">                chart: &#123;</span><br><span class="line">                    zoomType: &#39;x&#39;</span><br><span class="line">                &#125;,</span><br><span class="line">                title: &#123;</span><br><span class="line">                    text: selected + &#39;: 内存信息&#39;</span><br><span class="line">                &#125;,</span><br><span class="line">                subtitle: &#123;</span><br><span class="line">                    text: document.ontouchstart &#x3D;&#x3D;&#x3D; undefined ?</span><br><span class="line">                        &#39;Click and drag in the plot area to zoom in&#39; : &#39;Pinch the chart to zoom in&#39;</span><br><span class="line">                &#125;,</span><br><span class="line">                xAxis: &#123;</span><br><span class="line">                    type: &#39;datetime&#39;</span><br><span class="line">                &#125;,</span><br><span class="line">                yAxis: &#123;</span><br><span class="line">                    title: &#123;</span><br><span class="line">                        text: &#39;使用率 (%)&#39;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;,</span><br><span class="line">                legend: &#123;</span><br><span class="line">                    enabled: false</span><br><span class="line">                &#125;,</span><br><span class="line">                plotOptions: &#123;</span><br><span class="line">                    area: &#123;</span><br><span class="line">                        fillColor: &#123;</span><br><span class="line">                            linearGradient: &#123;</span><br><span class="line">                                x1: 0,</span><br><span class="line">                                y1: 0,</span><br><span class="line">                                x2: 0,</span><br><span class="line">                                y2: 1</span><br><span class="line">                            &#125;,</span><br><span class="line">                            stops: [</span><br><span class="line">                                [0, Highcharts.getOptions().colors[0]],</span><br><span class="line">                                [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get(&#39;rgba&#39;)]</span><br><span class="line">                            ]</span><br><span class="line">                        &#125;,</span><br><span class="line">                        marker: &#123;</span><br><span class="line">                            radius: 2</span><br><span class="line">                        &#125;,</span><br><span class="line">                        lineWidth: 1,</span><br><span class="line">                        states: &#123;</span><br><span class="line">                            hover: &#123;</span><br><span class="line">                                lineWidth: 1</span><br><span class="line">                            &#125;</span><br><span class="line">                        &#125;,</span><br><span class="line">                        threshold: null</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;,</span><br><span class="line"></span><br><span class="line">                series: [&#123;</span><br><span class="line">                    type: &#39;area&#39;,</span><br><span class="line">                    name: &#39;memory_rss&#39;,</span><br><span class="line">                    data: dataMem</span><br><span class="line">                &#125;]</span><br><span class="line">            &#125;);</span><br><span class="line">        &#125;);</span><br><span class="line"></span><br><span class="line">    &#125;);</span><br><span class="line">&#125;);</span><br><span class="line">&lt;&#x2F;script&gt;</span><br><span class="line">&lt;&#x2F;head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">&lt;div&gt;&lt;H2&gt;服务器监控信息&lt;&#x2F;H2&gt;&lt;&#x2F;div&gt;</span><br><span class="line"></span><br><span class="line">&lt;div id&#x3D;&quot;monitor&quot;&gt;</span><br><span class="line">    &lt;select id&#x3D;&quot;servers&quot;&gt;</span><br><span class="line">        &lt;option value&#x3D;&quot;server&quot;&gt;请选择要监控的服务器&lt;&#x2F;option&gt;</span><br><span class="line">        &lt;option value&#x3D;&quot;rotestZone01&quot;&gt;rotestZone01&lt;&#x2F;option&gt;</span><br><span class="line">        &lt;option value&#x3D;&quot;rotestZone02&quot;&gt;rotestZone02&lt;&#x2F;option&gt;</span><br><span class="line">    &lt;&#x2F;select&gt;</span><br><span class="line">    &lt;select id&#x3D;&quot;processes&quot;&gt;</span><br><span class="line">        &lt;option value&#x3D;&quot;process&quot;&gt;请选择要监控的进程&lt;&#x2F;option&gt;</span><br><span class="line">    &lt;&#x2F;select&gt;</span><br><span class="line">&lt;&#x2F;div&gt;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&lt;div id&#x3D;&quot;cpu&quot; style&#x3D;&quot;width: 1560px; height: 400px; margin: 0 auto&quot;&gt;&lt;&#x2F;div&gt;</span><br><span class="line">&lt;div id&#x3D;&quot;mem&quot; style&#x3D;&quot;width: 1560px; height: 400px; margin: 0 auto&quot;&gt;&lt;&#x2F;div&gt;</span><br><span class="line">&lt;&#x2F;body&gt;</span><br><span class="line">&lt;&#x2F;html&gt;</span><br></pre></td></tr></table></figure>

<h3 id="六、urls-py添加路由"><a href="#六、urls-py添加路由" class="headerlink" title="六、urls.py添加路由"></a>六、urls.py添加路由</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"># Author: Allan</span><br><span class="line"># Datetime: 2019-05-21</span><br><span class="line">from django.contrib import admin</span><br><span class="line">from django.urls import path</span><br><span class="line">from web import views</span><br><span class="line"></span><br><span class="line">urlpatterns &#x3D; [</span><br><span class="line">    # path(&#39;admin&#x2F;&#39;, admin.site.urls),</span><br><span class="line">    path(&#39;show_servers&#39;, views.show_servers),</span><br><span class="line">    path(&#39;show_procstat&#39;, views.show_procstat),</span><br><span class="line">]</span><br></pre></td></tr></table></figure>

<h3 id="七、运行程序，显示结果"><a href="#七、运行程序，显示结果" class="headerlink" title="七、运行程序，显示结果"></a>七、运行程序，显示结果</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"># python3 manager.py runserver</span><br></pre></td></tr></table></figure>

<p>CPU和内存信息</p>
<p><img src="http://iubest.gitee.io/pic/640-1601016028011.webp" alt="img"></p>
<p>进程信息</p>
<p><img src="http://iubest.gitee.io/pic/640-1601016027914.webp" alt="img"></p>
<p>往期精彩文章</p>
<p><a target="_blank" rel="noopener" href="http://mp.weixin.qq.com/s?__biz=MzU0NjEwMTg4Mg==&mid=2247484708&idx=1&sn=2a7230ade0ce0bd9059e92752e03ba18&chksm=fb638a31cc14032772d778f1a8fa5dc73f9aba6c99546c9ab25d9f91f706be3cff34572f0c1a&scene=21#wechat_redirect">kubernetes全栈技术+企业案例演示【带你快速掌握和使用k8s】</a></p>
<p><a target="_blank" rel="noopener" href="http://mp.weixin.qq.com/s?__biz=MzU0NjEwMTg4Mg==&mid=2247486272&idx=1&sn=e993bc259db899b79922863859d24bb2&chksm=fb638455cc140d43dd091b09efc0c744b82f32d905c78ce9be71aae8c6d324d625f110fa1093&scene=21#wechat_redirect">突破运维和开发瓶颈、Python、k8s、DevOps转型一网打尽！</a></p>
<p><a target="_blank" rel="noopener" href="http://mp.weixin.qq.com/s?__biz=MzU0NjEwMTg4Mg==&mid=2247486031&idx=1&sn=58003addbf36f2858f7d0dfbf887bb2a&chksm=fb63855acc140c4cf0346cc3433bc874e7cd37a5b17cf5254147a1b20b538cf70158f2234b0f&scene=21#wechat_redirect">python运维开发实战-基础篇
</a></p>
<p><a target="_blank" rel="noopener" href="http://mp.weixin.qq.com/s?__biz=MzU0NjEwMTg4Mg==&mid=2247486201&idx=1&sn=0d45a2660a7480d73cf72ba67fe52f3a&chksm=fb6385eccc140cfa90bef6759c768c94ac2ca904c827fb2dcd969858ba46b818145e76e09c62&scene=21#wechat_redirect">python运维和开发实战-高级篇</a></p>
<p><a target="_blank" rel="noopener" href="http://mp.weixin.qq.com/s?__biz=MzU0NjEwMTg4Mg==&mid=2247486210&idx=1&sn=078e172a34c22e5db1f57b17c21b2efe&chksm=fb638417cc140d011a058d7cf83795bf75cfc327acbb3727c968058ff2807874a26f87843080&scene=21#wechat_redirect">python运维和开发实战-安装和创建Django项目</a></p>
<p><a target="_blank" rel="noopener" href="http://mp.weixin.qq.com/s?__biz=MzU0NjEwMTg4Mg==&mid=2247484220&idx=1&sn=72ae437836108fbecbeb86752aad888c&chksm=fb638c29cc14053fafcb62be244f5a279052b8d159c9c530e73495cfd8ab97205988780d4aaa&scene=21#wechat_redirect">谈谈我的IT发展之路</a></p>
<p><a target="_blank" rel="noopener" href="http://mp.weixin.qq.com/s?__biz=MzU0NjEwMTg4Mg==&mid=2247484445&idx=1&sn=bf8928e7aae815b8e7f9ac56a67289ce&chksm=fb638b08cc14021e5e025f2f0b89d18ec5ef19f9dec4429a56f356e8b596d01095e313dab3e3&scene=21#wechat_redirect">Prometheus+Grafana+Alertmanager搭建全方位的监控告警系统-超详细文档</a></p>
<p><a target="_blank" rel="noopener" href="http://mp.weixin.qq.com/s?__biz=MzU0NjEwMTg4Mg==&mid=2247484264&idx=1&sn=4d74de0cb117c07ba7c73ea21c42bf94&chksm=fb638c7dcc14056b9f0261e05e4d36a057c4511fb5806222f71b7965c3573fed86672b2c93b7&scene=21#wechat_redirect">k8s1.18多master节点高可用集群安装-超详细中文官方文档</a></p>
<p><a target="_blank" rel="noopener" href="http://mp.weixin.qq.com/s?__biz=MzIzOTQ3NDg1Mw==&mid=2247483668&idx=1&sn=a7d0768b7eb034ef2e2f23e25b1b1845&chksm=e928c0dede5f49c878898e04329f08d8adf554397476283aaa3f2554f71a8bf20986755fbcc9&scene=21#wechat_redirect">linux面试题汇总</a></p>
<p>END</p>
 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          打赏
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>版权声明： </strong>
          
          本博客所有文章除特别声明外，著作权归作者所有。转载请注明出处！
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://example.com/2020/11/11/develop/Python%E9%87%87%E9%9B%86linux%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%95%B0%E6%8D%AE%E5%9C%A8Django%20Web%E7%95%8C%E9%9D%A2%E5%B1%95%E7%A4%BA/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/develop/" rel="tag">develop</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2020/11/11/deploy/%E9%AB%98%E5%8F%AF%E7%94%A8%E7%9A%84Redis%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E9%9B%86%E7%BE%A4%EF%BC%8C%E4%BB%8E%E7%90%86%E8%AE%BA%E5%88%B0%E5%AE%9E%E8%B7%B5/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            高可用的Redis主从复制集群，从理论到实践.md
          
        </div>
      </a>
    
    
      <a href="/2020/11/11/develop/Spring+Quartz%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">Spring+Quartz定时任务.md</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "",
    app_key: "",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "给我的文章加点评论吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
     
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2015-2020
        <i class="ri-heart-fill heart_icon"></i> TzWind
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        由 <a href="https://hexo.io" target="_blank">Hexo</a> 强力驱动
        <span class="division">|</span>
        主题 - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="Hexo"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" target="_blank" rel="noopener" href="http://www.baidu.com">百度</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2019/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


    
  </div>
</body>

</html>